//
//  OrderRepairCell.m
//  GasCome
//
//  Created by depelec on 2020/7/7.
//  Copyright © 2020 zfc. All rights reserved.
//

#import "OrderRepairCell.h"

@interface OrderRepairCell ()

@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UILabel *orderNumLab;
@property (nonatomic, strong) UILabel *statusLab;
@property (nonatomic, strong) UILabel *descLab;

@property (nonatomic, strong) UILabel *priceLab;
@end

@implementation OrderRepairCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setUI {
    
    self.backgroundColor = ColorF5;

    UIView *backView = [[UIView alloc] init];
    backView.backgroundColor = WhiteColor;
    backView.cornerRadius = 5;
    backView.clipsToBounds = YES;
    [self.contentView addSubview:backView];
    self.backView = backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
        make.leading.equalTo(self.contentView).offset(10);
        make.top.equalTo(self.contentView).offset(5);
    }];

    UIView *topView = [[UIView alloc] init];
    [backView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.equalTo(backView);
        make.height.mas_equalTo(40);
    }];

    UILabel *orderNumLab = [[UILabel alloc] init];
    orderNumLab.text = @"订单编号:";
    orderNumLab.font = [UIFont systemFontOfSize:13 weight:UIFontWeightBold];
    orderNumLab.textColor = Color999;
    [topView addSubview:orderNumLab];
    self.orderNumLab = orderNumLab;
    [orderNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(topView);
        make.leading.equalTo(topView).mas_offset(15);
    }];

    UILabel *statusLab = [[UILabel alloc] init];
    statusLab.text = @"";
    statusLab.textColor = PriceColor;
    statusLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    [topView addSubview:statusLab];
    self.statusLab = statusLab;
    [statusLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(topView);
        make.trailing.equalTo(topView).mas_offset(-15);
    }];
    
    UIImageView *imgV = [[UIImageView alloc] init];
    imgV.image = [UIImage imageNamed:@"order_img_repair"];
    [backView addSubview:imgV];
    [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom).offset(5);
        make.leading.equalTo(backView).offset(10);
        make.width.height.mas_equalTo(40);
    }];
    
    UILabel *typeLab = [[UILabel alloc] init];
    typeLab.text = @"维修订单";
    typeLab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    typeLab.textColor = Color333;
    [backView addSubview:typeLab];
    [typeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imgV);
        make.leading.equalTo(imgV.mas_trailing).offset(10);
    }];
    
    UILabel *descLab = [[UILabel alloc] init];
    descLab.text = @"";
    descLab.numberOfLines = 0;
    descLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    descLab.textColor = Color999;
    [backView addSubview:descLab];
    self.descLab = descLab;
    [descLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(typeLab.mas_bottom).offset(5);
        make.leading.equalTo(imgV.mas_trailing).offset(10);
        make.trailing.equalTo(backView).offset(-10);
    }];
    
    UILabel *priceLab = [[UILabel alloc] init];
    priceLab.text = @"";
    priceLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    priceLab.textColor = Color666;
    [backView addSubview:priceLab];
    self.priceLab = priceLab;
    [priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(descLab.mas_bottom).offset(15);
        make.trailing.equalTo(backView).offset(-10);
        make.bottom.equalTo(backView).offset(-15);
    }];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(gotoOrderRepairDetailWithOrder:)]) {
            [self.delegate gotoOrderRepairDetailWithOrder:self.orderDic];
        }
    }];
    [self addGestureRecognizer:tap];
}

- (void)setOrderDic:(NSDictionary *)orderDic {
    _orderDic = orderDic;
    NSInteger order_status = [orderDic[@"order_status"] integerValue];
    
    self.orderNumLab.text = [NSString stringWithFormat:@"订单编号:%@", self.orderDic[@"order_sn"]];
    [self configStatusLab];
    self.descLab.text = orderDic[@"seller_memo"];
    
    if (order_status == 4) {
        self.priceLab.text = [NSString stringWithFormat:@"¥%@", orderDic[@"user_cash"]];
        self.priceLab.textColor = PriceColor;
    } else {
        self.priceLab.text = @"待维修员确认价格";
        self.priceLab.textColor = Color666;
    }
}

- (void) configStatusLab {
    NSString *status = @"";
    NSInteger orderStatus = [self.orderDic[@"order_status"] integerValue];

    switch (orderStatus) {
        case 0:
            status = @"待付款";
            break;
        case 1:
            status = @"待发货";
            break;
        case 2:
            status = @"已发货";
            break;
        case 3:
            status = @"已收货";

            break;
        case 4:
            status = @"已完成";

            break;
        case -1:
            status = @"申请退款";
            break;
        case -2:
            status = @"退款中";
            break;
        case -3:
            status = @"退款完成";
            break;
        case -4:
            status = @"已关闭";
            break;
        case -5:
            status = @"撤销申请";
            break;
        case 101:
            status = @"待成团";
            break;
        case 104:
            status = @"待分配";
            break;
        case 105:
            status = @"待接单";
            break;
        case 106:
            status = @"待维修";
            break;
        default:
            break;
    }

    self.statusLab.text = status;

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
